package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CategoryListDataBean;
import com.fancy.learncenter.common.Constant;
import com.fancy.learncenter.ui.activity.CourseDetailActivity;
import com.fancy.learncenter.ui.activity.PlayAudioActivity;
import com.fancy.learncenter.ui.activity.PlayVedioActivity;
import com.fancy.learncenter.ui.activity.base.MallCommonH5Activity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;

import java.util.List;

/**
 * Created by Hyy on 2017/1/11.
 */

public class ActivityCategoryVedioAdapter extends CommonRecycleViewAdapter<CategoryListDataBean.ListBean> {
    Context context;

    public ActivityCategoryVedioAdapter(Context mContext, List<CategoryListDataBean.ListBean> itemDatas) {
        super(mContext, R.layout.activity_category_vedio_item, itemDatas);
        this.context = mContext;
    }


    @Override
    public void bindView(CustomViewHold customViewHold, final CategoryListDataBean.ListBean item, int position) {
        SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.simpleDraweeView);
        simpleDraweeView.setImageURI(item.getWholeShowResourceCoverImg());

        TextView time = customViewHold.getView(R.id.time);
        time.setText(item.getResourceDurationStr());

        TextView title = customViewHold.getView(R.id.title);
        title.setText(item.getShowResourceName());

        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //1 图片 2 视频 3 音频 4 视频h5 5 音频h5
                if (item.getType() == 2){

                        Intent intent = new Intent(context, PlayVedioActivity.class);
                        intent.putExtra(Constant.showResourceCoverImg, item.getWholeShowResourceCoverImg());
                        intent.putExtra(Constant.showResourceId, item.getShowResourceId());
                        intent.putExtra(Constant.showResourceName, item.getShowResourceName());
//                        intent.putExtra(Constant.intro, item.getName());?
                        context.startActivity(intent);
                    }else if (item.getType() == 3){ //音频
                        Intent intent = new Intent(context, PlayAudioActivity.class);
                        intent.putExtra(Constant.showResourceId,item.getShowResourceId());
                        intent.putExtra(Constant.showResourceCoverImg, item.getWholeShowResourceCoverImg());
                        context.startActivity(intent);

                }else if (item.getType() == 4 || item.getType() == 5){  //h5
                    Intent intent = new Intent(context, MallCommonH5Activity.class);
                    intent.putExtra(MallCommonH5Activity.URL_KEY, item.getWholePlayLink());
                    context.startActivity(intent);
                }

//                Intent intent = new Intent(mContext, PlayVedioActivity.class);
//
//                intent.putExtra(Constant.showResourceCoverImg, item.getWholeShowResourceCoverImg());
//                intent.putExtra(Constant.playLink, item.getWholePlayLink());
//                intent.putExtra(Constant.showResourceId, item.getShowResourceId());
//                intent.putExtra(Constant.showResourceName, item.getShowResourceName());
//                intent.putExtra(Constant.intro, item.getShowResourceName());
//
//                mContext.startActivity(intent);
            }
        });
    }
}
